<?php
class nxb extends database
{
    public function __construct()
    {
        $this->connection();
    }
    
    protected $_id;
    protected $_ten_nxb;
    protected $_dia_chi;
    protected $_dien_thoai;
    protected $_ghi_chu;
    
    public function set_id($i)
    {
        $this->_id = $i;
    }
    public function get_id()
    {
        return $this->_id;
    }
    
    public function set_ten_nxb($i)
    {
        $this->_ten_nxb = $i;
    }
    public function get_ten_nxb()
    {
        return $this->_ten_nxb;
    }
    
    public function set_dia_chi($i)
    {
        $this->_dia_chi = $i;
    }
    public function get_dia_chi()
    {
        return $this->_dia_chi;
    }
    
    public function set_dien_thoai($i)
    {
        $this->_dien_thoai = $i;
    }
    public function get_dien_thoai()
    {
        return $this->_dien_thoai;
    }
    
    public function set_ghi_chu($i)
    {
        $this->_ghi_chu = $i;
    }
    public function get_ghi_chu()
    {
        return $this->_ghi_chu;
    }
    
    function get_auto_increment()
    {
        $sql = "SHOW TABLE STATUS WHERE name = 'nha_xuat_ban'";
        $this->query($sql);
        if ($this->num_rows() != 0) {
            $row = $this->fetch();
            
            return $row['Auto_increment'];
        } else {
            return FALSE;
        }
    }
    
    function insert_nxb()
    {
        $sql = "INSERT INTO nha_xuat_ban(ten_nxb, dia_chi, dien_thoai, ghi_chu) VALUES('" . $this->get_ten_nxb() . "', '" . $this->get_dia_chi() . "', '" . $this->get_dien_thoai() . "', '" . $this->get_ghi_chu() . "')";
        $this->query($sql);
    }
    
    public function edit_nxb()
    {
        $sql = "UPDATE nha_xuat_ban SET ten_nxb=N'" . $this->get_ten_nxb() . "', dia_chi=N'" . $this->get_dia_chi() . "', dien_thoai=N'" . $this->get_dien_thoai() . "', ghi_chu=N'" . $this->get_ghi_chu() . "' WHERE id=N'" . $this->get_id() . "'";
        $this->query($sql);
    }
    
    public function delete_nxb()
    {
        $sql = "DELETE FROM nha_xuat_ban WHERE id='" . $this->get_id() . "'";
        $this->query($sql);
    }
    
    public function total_num_rows()
    {
        $sql = "SELECT * FROM nha_xuat_ban";
        $this->query($sql);
        $total_num_rows = $this->num_rows();
        
        return $total_num_rows;
    }
    
    public function getbyoption($options = array())
    {
        $select   = isset($options['select']) ? $options['select'] : '*';
        $where    = isset($options['where']) ? 'WHERE' . $options['where'] : '';
        $order_by = isset($options['order_by']) ? 'ORDER BY ' . $options['order_by'] : '';
        $limit    = isset($options['offset']) && isset($options['limit']) ? 'LIMIT ' . $options['offset'] . ',' . $options['limit'] : '';
        $sql      = "SELECT $select FROM nha_xuat_ban $where $order_by $limit";
        $this->query($sql);
        if ($this->num_rows() != 0) {
            while ($row = $this->fetch()) {
                $data[] = $row;
            }
            return $data;
        } else {
            return FALSE;
        }
    }
        
    public function getbyid()
    {
        $sql = "SELECT * FROM nha_xuat_ban WHERE id='" . $this->get_id() . "'";
        $this->query($sql);
        if ($this->num_rows() != 0) {
            $row = $this->fetch();
            
            return $row;
        } else {
            return FALSE;
        }
    }
}

?>